<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="box">
        <img src="banner.jpg" v-move>
    </div>
</body>

<script type="text/javascript">
    var vm = new Vue({
        el: '#box',
        directives: {
            move: function (el) {
                el.onmousedown = function (e) {
                    var initX = el.offsetLeft;
                    var initY = el.offsetTop;
                    var offsetX = e.clientX - initX;
                    var offsetY = e.clientY - initY;
                    document.onmousemove = function (e) {
                        var x = e.clientX - offsetX;
                        var y = e.clientY - offsetY;
                        var maxX = document.documentElement.clientWidth - el.offsetWidth;
                        var maxY = document.documentElement.clientHeight - el.offsetHeight;
                        if (x <= 0) {
                            x = 0
                        }
                        if (y <= 0) {
                            y = 0
                        }
                        if (x >= maxX) {
                            x = maxX
                        }
                        if (y >= maxY) {
                            y = maxY
                        }
                        el.style.left = x + "px";
                        el.style.top = y + "px";
                        return false;
                    }
                }
                document.onmouseup = function () {
                    document.onmousemove = null;
                }
            }
        },
        computed: {

        }
    })
</script>

<style type="text/css">
    img {
        position: absolute;
    }
</style>

</html>